package org.systemsbiology.bigquery.gae.utils;

import com.google.api.services.bigquery.model.Job;

import static org.apache.commons.lang.StringUtils.equalsIgnoreCase;

/**
 * @author hrovira
 */
public class JobUtils {

    public static boolean isSuccessful(Job job) {
        return (job != null && job.getStatus().getErrorResult() == null);
    }

    public static String getErrorMessage(Job job) {
        if (job != null && job.getStatus() != null && job.getStatus().getErrorResult() != null) {
            return job.getStatus().getErrorResult().getMessage();
        }
        return null;
    }

    public static boolean jobIsDone(Job job) {
        if (job != null && job.getStatus() != null) {
            return equalsIgnoreCase("DONE", job.getStatus().getState());
        }
        return false;
    }

}
